"""
--------------------------------------------------------------------------------
功能:封装自定义字体函数
日期:2025-06-03
作者:Unirobot
QQ交流群:811348489
寄语：代码中能遇见你，真好，有你，真好.
署名：有你同创智能机器人科技(北京)有限公司
--------------------------------------------------------------------------------
"""

import time

class CustomFont:
    def __init__(self):
        self.nothing = None

        #打印信息内容
        self.compony_msg="""
--------------------------------------------------------------------------------------
_    _       _   _______                     _                             
| |  | |     (_) |__   __|                   | |                            
| |  | |_ __  _     | | ___  _ __   __ _  ___| |__  _   _  __ _ _ __   __ _ 
| |  | | '_ \| |    | |/ _ \| '_ \ / _` |/ __| '_ \| | | |/ _` | '_ \ / _` |
| |__| | | | | |    | | (_) | | | | (_| | (__| | | | |_| | (_| | | | | (_| |
\____/|_| |_|_|    |_|\___/|_| |_|\__, |\___|_| |_|\__,_|\__,_|_| |_|\__,  |
                                    __/ |                              __/ |
                                    |___/                              |___/
作者:Unirobot
QQ交流群:811348489
寄语：代码中能遇见你，真好，有你，真好.
署名：有你同创智能机器人科技(北京)有限公司
--------------------------------------------------------------------------------------
        """

        self.imu_load_success="""
-------------------------
陀螺仪加载成功
-------------------------
        """

        self.arm_load_success="""
---------------------
机械臂初始化完成
---------------------
        """

        self.font_load_success="""
---------------------
自定义字体初始化完成
---------------------
        """

        self.ps2_load_success="""
---------------------
PS2初始化完成
---------------------
        """

        self.ps2_module_commond="""
---------------------------------------------------------------------------------------
                                  PS2手柄平放俯视图
._______________________________________________________________________________________.
|        L2:                                                                R2:         |
|        L1:                                                                R1:         |
|                                                                                       |
|        Up                                                                  Y          |
|        |                                                                   |          |
|Left----+----Right                                                     X----+----B     |
|        |                      SELECT         START                         |          |
|       Down                                                                 A          |
|                                       MODE                                            |
|             (-32767)                                    (-32767)                      |
|                |                                           |                          |
|                |                                           |                          |
|                |                                           |                          |
|(-32767)--------+-------> X(32767)           (-32767)-------+--------> X方向(32767)    |         
|                |                                           |                          |
|                |                                           |                          |
|                |                                           |                          |
|                v                                           v                          |
|            Y方向(32767)                               Y方向(32767)                    |
|                                                                                       |
|              左侧摇杆                                    右侧摇杆                     |
|_______________________________________________________________________________________|

---------------------------------------------------------------------------------------
        """

        self.ps2_arm_commond="""
---------------------------------------------------------------------------------------
                                  PS2手柄平放俯视图
._______________________________________________________________________________________.
|        L2:                                                                R2:         |
|        L1:                                                                R1:         |
|                                                                                       |
|        Up                                                                  Y          |
|        |                                                                   |          |
|Left----+----Right                                                     X----+----B     |
|        |                      SELECT         START                         |          |
|       Down                                                                 A          |
|                                       MODE                                            |
|             (-32767)                                    (-32767)                      |
|                |                                           |                          |
|                |                                           |                          |
|                |                                           |                          |
|(-32767)--------+-------> X(32767)           (-32767)-------+--------> X方向(32767)    |         
|                |                                           |                          |
|                |                                           |                          |
|                |                                           |                          |
|                v                                           v                          |
|            Y方向(32767)                               Y方向(32767)                    |
|                                                                                       |
|              左侧摇杆                                    右侧摇杆                     |
|_______________________________________________________________________________________|
左侧摇杆X方向向左拨动: 机械臂向左移动
左侧摇杆X方向向右拨动: 机械臂向右移动
左侧摇杆Y方向向上拨动: 机械臂向前移动
左侧摇杆Y方向向下拨动: 机械臂向后移动
右侧摇杆Y方向向上拨动: 机械臂向上移动
右侧摇杆Y方向向下拨动: 机械臂向下移动
左上角L1: 控制机械臂爪子闭合
右上角R1: 控制机械臂爪子张开
---------------------------------------------------------------------------------------
        """

    """
    -----------------------------------------------------------------------------
    终端打印带颜色, 背景色， 是否粗体, 是否带下划线的字体
    text: 需要打印的内容
    color: 需要打印的内容的字体颜色. 如果需要修改颜色, 改为对应颜色即可.
    bg_color: 需要打印的内容的背景色. 如果需要修改颜色, 改为对应颜色即可.
    bold: 需要打印的字体内容是否需要加粗. 如果需要加粗, 改为True即可.
    underline: 需要打印的字体内容是否需要添加下划线. 如果需要添加, 改为True即可.
    -----------------------------------------------------------------------------
    """
    def color_text(self, text, color=None, bg_color=None, bold=False, underline=False):
        codes = []
        if color:
            color_codes = {
                # 普通 8 色
                "black":30, "red":31, "green":32, "yellow":33,
                "blue":34, "magenta":35, "cyan":36, "white":37,
                # 亮色 8 色
                "bright_black":90, "bright_red":91, "bright_green":92,
                "bright_yellow":93, "bright_blue":94, "bright_magenta":95,
                "bright_cyan":96, "bright_white":97
            }
            codes.append(color_codes.get(color, 39))
        if bg_color:
            bg_codes = {
                "black":40, "red":41, "green":42, "yellow":43,
                "blue":44, "magenta":45, "cyan":46, "white":47,
                # 亮色背景
                "bright_black":100, "bright_red":101, "bright_green":102,
                "bright_yellow":103, "bright_blue":104, "bright_magenta":105,
                "bright_cyan":106, "bright_white":107
            }
            codes.append(bg_codes.get(bg_color, 49))
        if bold:
            codes.append(1)
        if underline:
            codes.append(4)
        
        if codes:
            return f"\033[{';'.join(map(str, codes))}m{text}\033[0m"
        else:
            return text